#include "../Libraries/UnitTest/UnitTest++.h"
#include "../Libraries/String/String.h"

#include "../HighLevel/SoundSystem.h"

using namespace UnitTest;

namespace {

	String names[] = { String("firstWave"), String("secondWave"), String("thirdWave") };
	String files[] = { String("wav1.wav"),  String("wav2.wav"),   String("wav3.wav") };

	TEST( Tool_System )
	{
		//SoundSystem*	pSys	= new SoundSystem();
		//ToolSystem*		pTool	= pSys->GetToolSystem();	// Get access to the tool system inside the sound system
		//

		//// Create some variables
		//CHECK( pTool->NewVariable("testVariable1", 0.0, 0.5) );
		//CHECK( pTool->NewVariable("testVariable2", 0.5, 1.0) );
		//CHECK( pTool->NewVariable("testVariable1", 0.0, 1.0) == false );		// Should return false because it's already defined
		//CHECK( pTool->GetVariableCount() == 2 );
		//CHECK( String( pTool->GetVariableName(0) ) == String( "testVariable1" ) );
		//CHECK( pTool->GetVariableMin(0) ==  0.0 );
		//CHECK( pTool->GetVariableMax(0) ==  0.5 );
		//CHECK( String( pTool->GetVariableName(1) ) == String( "testVariable2" ) );
		//CHECK( pTool->GetVariableMin(1) ==  0.5 );
		//CHECK( pTool->GetVariableMax(1) ==  1.0 );


		//// Create a new sound category and check that it returns true
		//CategoryHandle categoryID1 = pTool->NewCategory("CategoryName");
		//CategoryHandle categoryID2 = pTool->NewCategory("Category2");

		//CHECK( pTool->SetSoundPath(categoryID2, "../soundpath/") );

		//for( int i=0; i<3; ++i )
		//	CHECK( pTool->NewSoundFile(categoryID2, names[i].cstr(), files[i].cstr()) );


		//// Check that sound files were added successfully
		//CHECK( pTool->GetSoundFileCount( categoryID1 ) == 0 );
		//CHECK( pTool->GetSoundFileCount( categoryID2 ) == 2 );
		//
		//for( int i=0; i<3; ++i )
		//{
		//	CHECK( String( pTool->GetSoundName(categoryID2, i) )		== names[i] );
		//	CHECK( String( pTool->GetSoundFilename(categoryID2, i) )	== files[i] );
		//}

		//// Check that the sound paths were added successfully
		//CHECK( String( pTool->GetSoundPath( categoryID2 ) ) == String( "../soundpath/" ) );

		//// Add a graph
		//GraphHandle g = pTool->NewGraph("Graph1");
		//pTool->AddPoint(g, 0.1f, 0.3f);
		//pTool->AddPoint(g, 0.5f, 0.5f);

		//// Add some event stuff
		//EventHandle		e	= pTool->NewEvent("TestEvent");
		//SubEventHandle	se0	= pTool->AddSubEvent(e, "firstWave", 1.2345f); 
		//SubEventHandle	se1	= pTool->AddSubEvent(e, "secondWave", 3.445f);
		//pTool->AddSoundEffect(e,se0,"Graph1", "testVariable2", 1);
		//pTool->AddSoundEffect(e,se1, 1, 1, 1);


		//// Save the test xml file
		//CHECK( pTool->SaveSoundXML("current.xml") );
	}

	TEST( Tool_SystemLoad )
	{
		//SoundSystem*	pSys	= SoundSystem::Inst();
		//ToolSystem*		pTool	= pSys->GetToolSystem();	// Get access to the tool system inside the sound system

		//// Load the test xml file
		//CHECK( pTool->LoadSoundXML("current.xml") );

		//// Make sure that the data we loaded is correct
		//CHECK( pTool->GetSoundFileCount( 1 ) == 0 );
		//CHECK( pTool->GetSoundFileCount( 2 ) == 2 );
		//for( int i=0; i<3; ++i )
		//{
		//	CHECK( String( pTool->GetSoundName(2, i) )		== names[i] );
		//	CHECK( String( pTool->GetSoundFilename(2, i) )	== files[i] );
		//}
	}

	/*TEST( CreateHighLevelSystem )
	{
		SoundSystem* pSys = SoundSystem::Inst();

		// Loads and parses the xml file for later use
		pSys->LoadSoundXML("current.xml");
		
		// This would happen at the beginning of the level
		pSys->LoadCategory("CategoryName");
		
		float someFloat = 0.5;
		VariableHandle handle;
		pSys->GetVarHandle("Variable",handle);
		pSys->UpdateVariable(handle, someFloat);
		pSys->Update(1.0f);
		pSys->TriggerEvent("EventName");

		bool looping = false;
		float volume = 0.9f; // 1.0 = max, 0.0 = min


		// Direct sound manipulation
		FileHandle	fileID		= pSys->LoadSoundFile(L"file1.wav");
		ChannelHandle	soundID		= pSys->PlayFile(L"file2.wav", looping, volume);
		ChannelHandle	soundID2	= pSys->PlayFile(fileID, looping, volume);

		pSys->UnloadSoundFile(fileID);
		pSys->PlaySound(soundID);
		pSys->SetVolume(soundID,1.0f);
		pSys->StopSound(soundID);

		

	}*/

}
